﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ThuVien;
using System.Data;

namespace TranTekBE
{
    public partial class CategoryPriority : PagePopUp
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Page.IsPostBack == false)
            {
                this.LoadCategories();
            }
        }

        private void LoadCategories()
        {
            string sql = string.Empty;
            try
            {
                sql = "Select catName, CategoryISN From Vw_Category Order By catShowSeq ASC";
                DataSet ds = FunctionsUtils.Database.ExecuteQuery(sql);
                if (ds != null & ds.Tables.Count > 0)
                {
                    lbCategories.DataSource = ds;
                    lbCategories.DataBind();
                }
                else
                {

                }
            }
            catch (Exception ex)
            {
                ltError.Text = ex.Message;
            }
        }

        //protected void btnSubmit_Click(object sender, EventArgs e)
        //{
        //    ltError.Text = hdCatPriority.Value;
        //    if (hdCatPriority.Value.Length > 0)
        //    {
        //        try
        //        {
        //            FunctionsUtils.Database.ExecuteStoredProc("xp_category_priority", new string[] { "lstCategoryISN", "updatedBy" }, new object[] { hdCatPriority.Value, 0 });
        //            this.ClosePopupScripManager(true);
        //        }
        //        catch (Exception ex)
        //        {
        //            ltError.Text = ex.Message;
        //        }
        //    }
        //}

        private void SavePriority()
        {
            ltError.Text = string.Empty;
            if (hdCatPriority.Value.Length > 0)
            {
                try
                {
                    FunctionsUtils.Database.ExecuteStoredProc("xp_category_priority", new string[] { "lstCategoryISN", "updatedBy" }, new object[] { hdCatPriority.Value, 0 });
                    this.ClosePopupScripManager(true);
                }
                catch (Exception ex)
                {
                    ltError.Text = ex.Message;
                    log.WriteLog("Error in CategoryPriority (Save): {0} {1}", ex, ex.StackTrace);
                }
            }
        }

        protected void ControlClick_Command(object sender, CommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "Save":
                    this.SavePriority();
                    break;
            }
        }
    }
}
